package com.zzx.service;

import com.zzx.dao.FruitDao;
import com.zzx.model.pojo.Fruit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Random;

@Service
public class FruitService {
    @Autowired
    private FruitDao fruitDao;

    /**
     * 获取全部果园信息
     * @return
     */
    public List<Fruit> findAllFruit() {
        List<Fruit> fruits = fruitDao.findAllFruitInfo();
        return fruits;
    }

    /**
     * 新增果园
     * @param fruit
     */
    public void addFruit(Fruit fruit) {
        System.out.println("接受的参数");
        System.out.println(fruit);
        Random uuid = new Random();
        fruit.setId(uuid.nextInt(10000)); // 生成随机的uuid
        fruitDao.addFruitInfo(fruit);
    }

    /**
     * 编辑果园
     * @param fruit
     */
    public void editFruit(Fruit fruit) {
        fruitDao.editFruitInfo(fruit);
    }

    /**
     * 删除果园
     * @param id
     */
    public void delFruit(Integer id) {
        fruitDao.delFruitInfo(id);
    }
}